﻿using MiniFox.Log;
using MiniFox.Net.Configurations;
using MiniFox.Net.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniFox.Net.Ftp
{
    /// <summary>
    /// 
    /// </summary>
    public class FtpAdapter : WebAdapter<FtpService>
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="setting"></param>
        internal FtpAdapter(IFtpAdapterSetting setting) : base(setting)
        {
            UserName = setting.UserName;
            Password = setting.Password;
        }
        
        /// <summary>
        /// 
        /// </summary>
        public string UserName
        {
            get;
        }
        /// <summary>
        /// 
        /// </summary>
        public string Password
        {
            get;
        }
        /// <summary>
        /// 
        /// </summary>
        public override string FullHost
        {
            get
            {
                var host = $"{(SSL ? "ftps://" : "ftp://")}{Host}{((Port == (SSL ? 990 : 21) || Port <= ushort.MinValue || Port > ushort.MaxValue) ? string.Empty : (":" + Port))}";
                return host;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceSetting"></param>
        /// <returns></returns>
        protected override FtpService CreateDefaultService(IServiceSetting serviceSetting)
        {
            var service = new FtpService(serviceSetting, this);
            return service;
        }
    }
    
}
